package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmy.cultivate.entity.Dict;
import com.xmy.cultivate.mapper.DictMapper;
import com.xmy.cultivate.service.IDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author hpiggy
 * @since 2024-03-20
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {

    @Autowired
    DictMapper dictMapper;

    @Override
    public Dict getDictByNumAndType(Integer num,Integer type){
        QueryWrapper<Dict> dictQueryWrapper = new QueryWrapper<>();
        dictQueryWrapper.eq("num",num);
        dictQueryWrapper.eq("type",type);
        dictQueryWrapper.last("limit 1");
        return dictMapper.selectOne(dictQueryWrapper);
    }

    /**
     * 获取是否假期
     * @param num
     * @return
     */
    @Override
    public Integer getIsVacation(Integer num){
        Dict dict = this.getQuarter(num,19);
        return dict.getTag();
    }

    /**
     * 获取学期
     * @param num
     * @return
     */
    @Override
    public Dict getQuarter(Integer num,Integer type){
        QueryWrapper<Dict> dictQueryWrapper = new QueryWrapper<>();
        dictQueryWrapper.eq("num",num);
        dictQueryWrapper.eq("type",type);
        dictQueryWrapper.last("limit 1");
        return dictMapper.selectOne(dictQueryWrapper);
    }
}
